import React from 'react';
import PropTypes from 'prop-types';
import AtPath from '@txdfe/at-path';

export default class PathEllipsis extends React.PureComponent {
  static propTypes = {
    path: PropTypes.string,
    size: PropTypes.string,
    noCursorPointer: PropTypes.bool,
    isLastItemMoreImportant: PropTypes.bool,
  };

  static defaultProps = {
    path: '',
    size: 'medium',
    noCursorPointer: true,
    isLastItemMoreImportant: true,
  };

  render() {
    const { path, size, noCursorPointer, isLastItemMoreImportant, ...others } = this.props;
    const dataSource = path.split('/').map((item) => {
      return { name: item };
    });

    return (
      <AtPath
        dataSource={dataSource}
        separator={'/'}
        size={size}
        noCursorPointe={noCursorPointer}
        isLastItemMoreImportant={isLastItemMoreImportant}
        {...others}
      />
    );
  }
}
